(* init for interactive mode *)
_require "../../src/basis.smi"
_require "../../src/smlformat-lib.smi"
_require local "../../src/basis/main/SMLSharp_Runtime.smi"
_require local "../../src/compiler/libs/config/main/Config.smi"
_require local "../../src/compiler/data/symbols/main/Loc.smi"
_require local "../../src/compiler/data/control/main/Control.smi"
_require "../../src/compiler/extensions/usererror/main/UserError.ppg.smi"
_require "../../src/compiler/libs/toolchain/main/Filename.smi"
_require "../../src/compiler/compilerIRs/absyn/main/InterfaceName.ppg.smi"
_require local "../../src/compiler/libs/toolchain/main/CoreUtils.smi"
_require local "../../src/compiler/libs/toolchain/main/LLVMUtils.smi"
_require local "../../src/compiler/libs/toolchain/main/TempFile.smi"
_require local "../../src/compiler/compilePhases/parser/main/Parser.smi"
_require local "../../src/compiler/compilePhases/toplevel/main/Top.smi"
_require local "../../src/compiler/compilePhases/main/main/Main.smi"
_require local "../../src/compiler/compilePhases/main/main/Interactive.smi"
_require local "../../src/compiler/compilePhases/main/main/UserFileMap.smi"
_require local "../../src/compiler/extensions/reflection/main/ReifiedTerm.ppg.smi"

(* needed to make the prelude library available *)
_require "../../src/prelude.smi" init

structure Compiler =
struct

  (* some errors occurred during initialization *)
  exception Init of string

  (* some compile errors or warnings occurred during compilation.
   * The first "string" is the formatted error message. *)
  exception CompileError of string * UserError.errorInfo list

  (* exceptions raised by "execute" when the program aborts *)
  exception Failure of int * string
  exception CoreDumped of string
  exception Signaled of int * string

  (* found an uncaught exception during interactive execution
   * The first "string" is the formatted error message. *)
  exception UncaughtException of string * exn

  type srcfile = string
  type objfiles (= list)
  type exefile (= string)
  type error = UserError.errorInfo

  val systemBaseDir : Filename.filename
  val dataDir : Filename.filename
  val dataFile : string -> Filename.filename

  (* initialize this driver *)
  val init : unit -> unit

  (* compile and execute the given SML# program.
   * These are provided for compiler and library tests.
   * The entire source code is given to the compiler at once.
   *)
  val eval : string -> unit
  val eval' : string -> {errors : error list}
  val evalFile : string -> unit
  val evalFile' : string -> {errors : error list}

  (* emulation of interactive mode (with the value printer).
   * These are provided for interactive mode and value printer tests.
   * The input code is splitted by semicolons and is read step-by-step.
   *)
  val interactive : string -> {prints : string list}
  val interactive' : string -> {errors : error list, prints : string list}
  val interactiveFile : string -> {prints : string list}
  val interactiveFile' : string -> {errors : error list, prints : string list}

  (* batch compilation *)
  val compile : string list -> objfiles
  val compile'
      : string list
        -> {objfiles : objfiles,
            errors : error list,
            dependency : InterfaceName.file_dependency option list}
  val link : string -> objfiles -> exefile
  val link' : string
              -> objfiles
              -> {exefile : exefile,
                  errors : error list,
                  dependency : InterfaceName.file_dependency option}
  val execute : exefile -> unit

  val raiseCompileError : error list -> 'a
  val checkCompileError : ['a#{errors : error list}. 'a -> 'a]

end
